<template>
  <div class="menu-wrapper">
    <div class="top-menu">
      <div class="container">
        <div class="contact">
          <span>
            <i class="el-icon-s-comment"></i>
            qiutie@ieee.org
          </span>
          <span>
            <i class="el-icon-phone"></i>
            +86-22-85356782
          </span>
        </div>
        <div
          class="language-button"
          @click="handleChangeLanguage"
        >{{$store.state.language === 'zh-CN' ? 'English' : '中文'}}</div>
      </div>
    </div>
    <div class="container">
      <div class="logo">
        <img :src='require("../assets/tanklab-white.png")' />
        <h3 v-if="$store.state.language === 'zh-CN'">智慧物联网与大数据研究小组</h3>
        <h3 v-else>Smart IoT & Big Data Research Group</h3>
      </div>
      <div
        class="sub-menu-button"
        :class="{active: subMenuButton}"
        @click="handleSubMenuButtonClick"
      >
        Menu
        <i class="el-icon-arrow-up" />
      </div>
      <div class="sub-menu" :class="{active: subMenuButton}" @mouseleave="handleSubMenuMouseOut">
        <div
          @click="handleSubMenuMouseOut"
          class="sub-menu-item"
          v-for="(item, _ ) in menuItemList"
          :key="_"
        >
          <router-link
            :to="item.target"
          >{{$store.state.language === 'zh-CN' ? item.text : item.enText}}</router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang='ts'>
import { Component, Vue } from "vue-property-decorator";

@Component
export default class Menu extends Vue {
  private menuItemList: object[] = [
    {
      text: "首页/Home",
      enText: "Home",
      target: "/Home"
    },
    {
      text: "科研/Research",
      enText: "Research",
      target: "/Research"
    },
    {
      text: "论文/Publications",
      enText: "Publications",
      target: "/Publications"
    },
    {
      text: "学生/Students",
      enText: "Students",
      target: "/Students"
    },
    {
      text: "图集/Gallery",
      enText: "Gallery",
      target: "/Gallery"
    }
  ];

  private subMenuButton: boolean = false;

  mounted() {
    if (document.documentElement.clientWidth < 640) {
      this.$store.commit("changeMobile");
    }
  }
  handleChangeLanguage() {
    this.$store.commit("changeLanguage");
  }

  handleSubMenuButtonClick() {
    this.subMenuButton = !this.subMenuButton;
  }

  handleSubMenuMouseOut() {
    if (this.subMenuButton) {
      this.subMenuButton = false;
    }
  }
}
</script>

<style lang='scss'>
.menu-wrapper {
  background: #f5ae54;
  .top-menu {
    height: 70px;
    background: #113f6c;
    line-height: 70px;
    color: white;
    display: flex;
    justify-content: space-around;
    margin: auto;
    .contact {
      span:first-child {
        margin-right: 20px;
      }
    }
    .language-button {
      width: 710px;
      text-align: right;
      cursor: pointer;
    }
  }
  .container {
    display: flex;
    justify-content: space-around;
    margin: auto;
    padding: 0px;
  }
  .logo {
    padding-top: 8px;
    width: 240px;
    text-align: center;
    img {
      height: 40px;
    }
    h3 {
      position: absolute;
      margin: 0;
    }
  }
  .sub-menu-button {
    display: none;
  }
  .sub-menu {
    display: flex;
    width: 800px;
    justify-content: space-between;
    .sub-menu-item {
      margin-right: 20px;
      box-sizing: border-box;
      text-align: right;
      &:last-child {
        margin-right: 0;
      }
    }
    a {
      text-decoration: none;
      color: white;
      font-size: 18px;
      line-height: 85px;
      font-weight: bold;
      border-radius: 10px;
      padding: 10px;
      &:hover,
      &.router-link-exact-active {
        background: rgba(255, 255, 255, 0.3);
        color: #113f6c;
      }
    }
  }
}

@media screen and (max-width: 1100px) {
  .menu-wrapper {
    position: relative;
    margin-bottom: 55px;
    .logo {
      height: 50px;
      img {
        height: 40px;
        width: auto;
      }
      h3 {
        position: absolute;
        margin-top: 15px;
        width: 100%;
        text-align: center;
        left: 0;
      }
    }
    .top-menu {
      height: 50px;
      line-height: 50px;
      justify-content: space-between;
      padding: 0 22px;
      font-size: 12px;
      .contact {
        text-align: left;
      }
      .language-button {
        width: auto;
      }
    }
    .sub-menu {
      position: absolute;
      z-index: 1001;
      right: 0px;
      top: 115px;
      background: #f5ae54;
      width: 170px;
      display: block;
      opacity: 0;
      height: 0;
      pointer-events: none;
      transition: all ease-in-out 0.3s;
      .sub-menu-item {
        width: 100%;
        text-align: center;
        margin-right: 0;
        a {
          font-size: 16px;
          line-height: 50px;
        }
      }
      &.active {
        opacity: 1;
        height: 250px;
        pointer-events: auto;
      }
    }
    .sub-menu-button {
      display: block;
      position: absolute;
      font-size: 18px;
      line-height: 63px;
      right: 20px;
      color: white;
      font-weight: bold;
      width: 170px;
      text-align: right;
      cursor: pointer;
      &:hover,
      &.active {
        color: #113f6c;
      }
      &.active {
        .el-icon-arrow-up {
          transform: rotateZ(180deg) translateY(-3px);
        }
      }
    }
    .el-icon-arrow-up {
      margin-left: 5px;
      transition: transform ease-in-out 0.3s;
    }
  }
}
</style>
